<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <div id="app">
            <div>
                <label>
                    id
                    <input type="text"  v-model='id'>
                </label>
                <label>
                    name
                    <input type="text" v-model='name'>
                </label>
                <button @click='add'>添加</button>
                <h1>
                    {{id}} ------- {{name}}
                </h1>
                <ul>
                    <!-- <li :key='index' v-for='(item,index) in list'>
                        <input type="checkbox">
                        id:{{item.id}} --------- 姓名 {{item.name}}
                    </li>   -->
                    <li :key='item.id' v-for='(item,index) in list'>
                        <input type="checkbox">
                        id:{{item.id}} --------- 姓名 {{item.name}}
                    </li>
                </ul>
            </div>
        </div>
    
    </div>


    <script>

        var app = new Vue({
            el: '#app',
            data: {
                message: 'Hello Vue22222!',
                id: '',
                name: '',
                list: [
                    {
                        id: 1,
                        name: '张无忌'
                    },
                    {
                        id: 2,
                        name: '乔峰'
                    }, {
                        id: 3,
                        name: '令狐冲'
                    }
                    ,
                    {
                        id: 4,
                        name: '杨过'
                    }
                ]
            },
            methods:{
                add(){
                    console.log('add')
                    var temobj = {id:this.id,name:this.name}
                    // this.list.push(temobj)
                    this.list.unshift(temobj)
                }
            }
        })

        console.log('app', app)

    </script>
</body>

</html>